package com.blrs.framework.listener;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;


/**
 * @Author yuxiang.chen
 * @Date 16:00 2023/5/25 16
 **/

@Component
public class RedisListeners implements MessageListener {

    private static final Logger log = LoggerFactory.getLogger(RedisListeners.class);


    @Override
    public void onMessage(Message message, byte[] pattern) {
        String expiredKey = message.toString();
        log.info(expiredKey);
        if (expiredKey.contains("TIME_OUT_KEY")) { // 判断是否是想要监听的过期key
            log.info("redis TIME_OUT_KEY过期：{}", expiredKey);
            //pattern:__keyevent@*__:expired
           // log.info("redis pattern:{}", new String(pattern, StandardCharsets.UTF_8));
            // TODO 业务逻辑
        }

    }
}
